/// 饮食统计数据模型
class FoodStatistics {
  final String? recordDate;
  final String? weekName;
  final String? dateStart;
  final String? dateEnd;
  final List<FoodDayVO>? foodDayVOS;
  final List<FoodVO>? foodVOS;

  const FoodStatistics({
    this.recordDate,
    this.weekName,
    this.dateStart,
    this.dateEnd,
    this.foodDayVOS,
    this.foodVOS,
  });

  factory FoodStatistics.fromMap(Map<String, dynamic> map) {
    return FoodStatistics(
      recordDate: map['recordDate'] as String?,
      weekName: map['weekName'] as String?,
      dateStart: map['dateStart'] as String?,
      dateEnd: map['dateEnd'] as String?,
      foodDayVOS: map['foodDayVOS'] != null
          ? (map['foodDayVOS'] as List)
              .map((item) => FoodDayVO.fromMap(item as Map<String, dynamic>))
              .toList()
          : null,
      foodVOS: map['foodVOS'] != null
          ? (map['foodVOS'] as List)
              .map((item) => FoodVO.fromMap(item as Map<String, dynamic>))
              .toList()
          : null,
    );
  }
}

/// 每日饮食数据
class FoodDayVO {
  final String? recordDate;
  final String? weekName;
  final List<FoodVO>? foodVOS;

  const FoodDayVO({
    this.recordDate,
    this.weekName,
    this.foodVOS,
  });

  factory FoodDayVO.fromMap(Map<String, dynamic> map) {
    return FoodDayVO(
      recordDate: map['recordDate'] as String?,
      weekName: map['weekName'] as String?,
      foodVOS: map['foodVOS'] != null
          ? (map['foodVOS'] as List)
              .map((item) => FoodVO.fromMap(item as Map<String, dynamic>))
              .toList()
          : null,
    );
  }
}

/// 单条饮食记录
class FoodVO {
  final String? foodName;
  final String? imageUrl;
  final String? recordTime;
  final double? calories;
  final double? protein;
  final double? carbohydrate;
  final double? fat;
  final String? mealType;

  const FoodVO({
    this.foodName,
    this.imageUrl,
    this.recordTime,
    this.calories,
    this.protein,
    this.carbohydrate,
    this.fat,
    this.mealType,
  });

  factory FoodVO.fromMap(Map<String, dynamic> map) {
    return FoodVO(
      foodName: map['foodName'] as String?,
      imageUrl: map['imageUrl'] as String?,
      recordTime: map['recordTime'] as String?,
      calories: (map['calories'] as num?)?.toDouble(),
      protein: (map['protein'] as num?)?.toDouble(),
      carbohydrate: (map['carbohydrate'] as num?)?.toDouble(),
      fat: (map['fat'] as num?)?.toDouble(),
      mealType: map['mealType'] as String?,
    );
  }

  /// 获取用餐类型文本
  String getMealTypeText() {
    if (mealType == null || mealType!.isEmpty) return '';
    switch (mealType) {
      case '早餐':
      case '午餐':
      case '晚餐':
      case '加餐':
        return mealType!;
      default:
        return mealType!;
    }
  }
}
